module.exports = (app) => {
  const {
    STRING, INTEGER, TEXT, DATE
  } = app.Sequelize;

  const Template = app.model.define('Template', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    uuid: { type: STRING(36), unique: true },
    title: { type: STRING(100) }, // 问卷标题
    description: { type: TEXT }, // 问卷描述
    epilog: { type: TEXT }, // 问卷结语
    prefixion: { type: STRING(100) }, // 问卷编号开头
    logo: { type: STRING(255) }, // 问卷图标地址
    createdAt: { type: DATE, field: 'created_at' },
    updatedAt: { type: DATE, field: 'updated_at' },
  }, {
    tableName: 'templates'
  });

  Template.associate = () => {
    app.model.Template.hasMany(app.model.Questionnaire, {
      foreignKey: 'fk_template',
      sourceKey: 'id',
    });
  };

  return Template;
};
